# -*- coding: utf-8 -*-
"""
Created on Wed May 17 15:06:38 2017

@author: qiang.qian
"""


import pandas as pd
import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.offline as local 

import datetime
today = datetime.date.today().strftime("%Y%m%d")

df = pd.read_table('b:\\active_lost_data_1_' + today + '.txt',index_col='order_flag')
x = list(range(1,9))


y = [7,6,5,4,3,2,1]
name = ['']

traces = []

for s in range(1,8):
    traces.append(
        go.Scatter(
                x = x,
                y = [8-s]*8,
                text= ["{:,}".format(i) for i in df['total_entry'].tolist()],
                mode='markers',
                name='入口',
                marker=dict(
                    size= np.array(df.ix[:]['total_entry'].tolist())/100,
                    sizemode='area',
                ) 
            
            )
    )

trace1 = go.Scatter(
    x = x,
    y = [7]*8,
    text= ["{:,}".format(i) for i in df['total_entry'].tolist()],
    mode='markers',
    name='入口',
    marker=dict(
        size= np.array(df.ix[:]['total_entry'].tolist())/100,
        sizemode='area',
    )
)

trace2 = go.Scatter(
    x = x,
    y = [6]*8,
    text= ["{:,}".format(i) for i in df['apply'].tolist()],
    mode='markers',
    marker=dict(
        size= np.array(df.ix[:]['apply'].tolist())/100,
        sizemode='area',
    )
)

trace3 = go.Scatter(
    x = x,
    y = [5]*8,
    text= ["{:,}".format(i) for i in df['pass'].tolist()],
    mode='markers',
    marker=dict(
        size= np.array(df.ix[:]['pass'].tolist())**0.5,
        sizemode='area',
    )
)

trace4 = go.Scatter(
    x = x,
    y = [4]*8,
    text= ["{:,}".format(i) for i in df['card'].tolist()],
    mode='markers',
    marker=dict(
        size= np.array(df.ix[:]['card'].tolist())**0.5,
        sizemode='area',
    )
)

trace5 = go.Scatter(
    x = x,
    y = [3]*8,
    text= ["{:,}".format(i) for i in df['active'].tolist()],
    mode='markers',
    marker=dict(
        size= np.array(df.ix[:]['active'].tolist())**0.5,
        sizemode='area',
    )
)

trace6 = go.Scatter(
    x = x,
    y = [2]*8,
    text= ["{:,}".format(i) for i in df['finish'].tolist()],
    mode='markers',
    marker=dict(
        size= np.array(df.ix[:]['finish'].tolist())**0.5,
        sizemode='area',
    )
)

trace7 = go.Scatter(
    x = x,
    y = [1]*8,
    text= ["{:,}".format(i) for i in df['success'].tolist()],
    mode='markers',
    marker=dict(
        size= np.array(df.ix[:]['success'].tolist())**0.5,
        sizemode='area',
    )
)

data = [trace1,trace2,trace3,trace4,trace5,trace6,trace7]
local.plot(data, filename='bubblechart-size-ref')
